<!DOCTYPE html "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">


<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">应用名称：</label>
                            <div class="col-sm-10">
                                <input id="appName" name="appName" class="form-control" type="text" maxlength="50" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">应用代码：</label>
                            <div class="col-sm-10">
                                <input id="appCode" name="appCode"  tabindex="2" class="form-control" type="text" maxlength="15" placeholder="">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">公众号：</label>
                            <div class="col-sm-10">
                                <input id="mpNo" name="mpNo"  tabindex="2" class="form-control" type="text" maxlength="30" placeholder="123456789">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">公众名称：</label>
                            <div class="col-sm-10">
                                <input id="mpName" name="mpName"  tabindex="2" class="form-control" type="text" maxlength="180" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">客服QQ：</label>
                            <div class="col-sm-10">
                                <input id="customQq" name="customQq"  tabindex="2" class="form-control" type="text" maxlength="15" placeholder="123456">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">安装包下载地址：</label>
                            <div class="col-sm-10">
                                <input id="packageDownloadUrl" name="packageDownloadUrl"  tabindex="2" class="form-control" type="text" maxlength="180" placeholder="http://...">
                            </div>
                        </div>


                        <div class="text-right form-group">
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    $().ready(function () {
        validateRule();

        // $('.summernote').summernote({
        //     height: '220px',
        //     lang: 'zh-CN',
        //     callbacks: {
        //         onImageUpload: function (files, editor, $editable) {
        //             sendFile(files);
        //         }
        //     }
        // });
    });


    $.validator.setDefaults({
        submitHandler: function () {
            save();
        }
    });


    function save() {
        //var content_sn = $("#content_sn").summernote('code');
        //$("#productDetail").val(content_sn);
        $.ajax({
            cache: true,
            type: "POST",
            url: "/app/apply/save",
            data: $('#signupForm').serialize(), // 你的formid
            async: false,
            success: function (data) {
                layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
            }
        });
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                appName: {
                    required: true,
                    remote : {
                        url : "/app/apply/appNameCodeExit", // 后台处理程序
                        type : "post", // 数据发送方式
                        dataType : "json", // 接受数据格式
                        data : { // 要传递的数据
                            appName : function() {
                                return  $.trim($("#appName").val());
                            }
                        }
                    }
                },
                appCode:{
                    required: true,
                    remote : {
                        url : "/app/apply/appNameCodeExit", // 后台处理程序
                        type : "post", // 数据发送方式
                        dataType : "json", // 接受数据格式
                        data : { // 要传递的数据
                            appCode : function() {
                                return $.trim($("#appCode").val());
                            }
                        }
                    }
                },
                mpNo:{
                    required: true
                },
                mpName:{
                    required: true
                },
                customQq:{
                    required: true
                },
                packageDownloadUrl:{
                    required: true
                }
            },
            messages: {
                appName: {
                    required: icon + "必填",
                    remote : icon + "应用名称已存在"
                },
                appCode: {
                    required: icon + "必填",
                    remote : icon + "应用代码已存在"
                },
                mpNo: {
                    required: icon + "必填"
                },
                mpName: {
                    required: icon + "必填"
                },
                customQq: {
                    required: icon + "必填"
                },
                packageDownloadUrl: {
                    required: icon + "必填"
                }
            }
        })
    }

</script>
</body>
</html>